package com.bwie.home.backstage.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.home.backstage.entity.vo.ChaXun;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.Query;

import com.bwie.home.backstage.dao.HousesDao;
import com.bwie.home.backstage.entity.HousesEntity;
import com.bwie.home.backstage.service.HousesService;


@Service("housesService")
public class HousesServiceImpl extends ServiceImpl<HousesDao, HousesEntity> implements HousesService {


    @Override
    public PageUtils queryPage(Map<String, Object> params, HousesEntity housesEntity) {
        QueryWrapper<HousesEntity> wrapper = new QueryWrapper<>();
        if (housesEntity!=null){
            if (housesEntity.getHousesArea()!=null && !"".equals(housesEntity.getHousesArea())){
                wrapper.like("houses_area",housesEntity.getHousesArea());
            }
            if (housesEntity.getHousesPrice()!=null && !"".equals(housesEntity.getHousesPrice())){
                wrapper.like("houses_price",housesEntity.getHousesPrice());
            }
            if (housesEntity.getTypeId()!=null && !"".equals(housesEntity.getTypeId())){
                wrapper.like("type_id",housesEntity.getTypeId());
            }
        }
        IPage<HousesEntity> page = this.page(
                new Query<HousesEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }


    @Override
    public PageUtils HousesList(Map<String, Object> params) {
        IPage<HousesEntity> page = null;
        Integer pageIndex = 1;
        Integer pageSize =2;

        ChaXun chaXun = new ChaXun();
        if(params!=null){
            //判断模糊查询如果不为空赋值于值,否知空值
            if(( params.get("name")!=null && params.get("name")!="")){
                chaXun.setName((String)params.get("name"));
            }
            if(( params.get("housesProvince")!=null && params.get("housesProvince")!="")){
                chaXun.setHousesProvince((String)params.get("housesProvince"));
            }
            if(( params.get("housesCity")!=null && params.get("housesCity")!="")){
                chaXun.setHousesCity((String)params.get("housesCity"));
            }
            if(( params.get("housesCounty")!=null && params.get("housesCounty")!="")){
                chaXun.setHousesCounty((String)params.get("housesCounty"));
            }

            //如果不为空赋值 pageIndex  pageSize
            if( params.get("pageIndex")!=null &&  (Integer)params.get("pageIndex")>0 &&  params.get("pageSize")!=null && (Integer) params.get("pageSize")>0){
                pageIndex = (Integer)params.get("pageIndex");
                pageSize = (Integer) params.get("pageSize");
            }
            //为空走默认
            Page<HousesEntity> Doctor =
                    new Page<>(pageIndex, pageSize);
            page = baseMapper.HousesList(Doctor,chaXun);




        }
        assert page != null;
        return new PageUtils(page);
    }

}